import logging
import yagmail
from BeautifulReport import BeautifulReport


class Tools:
    def log(self, logname, loglevel=logging.DEBUG):
        sh = logging.StreamHandler()
        fh = logging.FileHandler(logname)
        logging.basicConfig(level=loglevel,handlers=[sh,fh],
                            format='%(asctime)s %(name)s %(filename)s %(lineno)d %(message)s')

    def report(self, suite, description, report_dir, filename):
        baogao = BeautifulReport(suite)
        baogao.report(description=description, report_dir=report_dir, filename=filename)
        return baogao

    def email(self, subject, contents, attachments):
        youjian = yagmail.SMTP(user='755568124@qq.com', password='huvqsilecmxobeej', host='smtp.qq.com', port=465)
        youjian.send(to='755568124@qq.com', subject=subject, contents=contents, attachments=attachments)
        youjian.close()